/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - geometry/mesh
// Copyright( c) 2015.  All Rights Reserved
//
// File:		AEMeshManager.h
// Author:		Gianluca Belardelli
// Date:		05/05/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEMESHMANAGER_H_
#define _AEMESHMANAGER_H_

class AEBaseMesh;
class AEStaticMesh;

/// \brief
///   Resource Manager for meshes
class AEMeshManager : public AEResourceManager
{
// Methods
protected:

	virtual AEResource *LoadResource(const char *szFilename);
	AE_DLLIMPEXP virtual AEResource *CreateResource( const char *lpFilename, AEResourceSnapshotEntry *lpExtraInfo );

public:
	/// \brief
	///   Internal: Constructor of the mesh manager.
	AEMeshManager( const char *lpManagerName, AEINT32 nFlags, AEINT32 nMemLimit );

	/// \brief
	///   Method to load a static mesh from a .vmesh file.
	AE_DLLIMPEXP AEStaticMesh *LoadStaticMeshFile( const char *lpFilename ); 

	/// \brief
	///   Method to load a dynamic mesh from a .model file.
	//AE_DLLIMPEXP VDynamicMesh *LoadDynamicMeshFile(const char *szFilename);

	/// \brief
	///   Method to find a mesh file of specified type in the manager. Similar to VResourceManager::GetResourceByName but also checks the type
	AE_DLLIMPEXP AEBaseMesh *FindMeshFile( const char *lpFilename, AEMeshType eType );

	/// \brief
	///   Returns a pointer to the global static mesh manager
	AE_DLLIMPEXP static AEMeshManager* GetMeshManager( void );

	/// \brief
	///   Merges a list of existing (dynamic) meshes into a new one
	/// 
	/// The merged mesh can be used for entities. Since the animation system can perform skeletal remapping, the original animation sequences can
	/// be applied to the new mesh. This method is thus very useful to bake the equipment parts (several entities) into a new mesh to reduce the number
	/// of entities in the scene. However, this optimization sacrifices memory, as the new mesh consists of unique geometry.
	/// The new number of vertices and triangles matches the sum of all subparts. No merging of vertices takes place 
	/// (merging of skeletons and materials is optional and defined by the respective MeshMergeInfo_t members).
	/// Merged meshes cannot be saved to file by the runtime. Quite naturally, unloading the resource is not supported.
	/// This function outputs a strict 1:1 relation between surfaces and submeshes, even when the input models have more submeshes per material. All
	/// original submeshes that belong to merged surfaces will be merged as well. This implies that this function does not split submeshes according to primitive counts,
	/// so the new primitive count might exceed the supported draw call sizes on specific platforms (e.g. 32k triangles).
	///
	/// \param szNewName
	///   The new name of the mesh to appear it in the resource manager. Must be !=NULL, but does not necessarily have to be unique name
	/// 
	/// \param pInfoList
	///   A pointer to an array of info structures that hold information about meshes to merge. Each entry in the list represents one mesh to bake
	/// 
	/// \param iInfoCount
	///   Number of array entries in pInfoList.
	/// 
	/// \param pReferenceSkeleton
	///   An optional reference skeleton. If not specified, the first skeleton of a mesh in the list is used.
	/// 
	/// \param pLog
	///   Optional log that receives notifications about errors
	/// 
	/// \return
	///   VisModel_cl *pNewMesh : A new mesh instance baked form the sources. Can be NULL if an error has occurred (which is reported to pLog instance).
	//AE_DLLIMPEXP VDynamicMesh* MergeDynamicMeshes(const char *szNewName, MeshMergeInfo_t *pInfoList, int iInfoCount, VisSkeleton_cl *pReferenceSkeleton = NULL, hkvLogInterface* pLog = hkvGlobalLog::GetInstance());
};

#endif // _AEMESHMANAGER_H_
